package com.hsgene.message.config;

import com.aliyun.openservices.ons.api.ONSFactory;
import com.aliyun.openservices.ons.api.Producer;
import com.aliyun.openservices.ons.api.PropertyKeyConst;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @author wxf
 * @date 2018/10/29 11:54
 **/
@Configuration
public class MQProducer extends MQAkSk {

    @Value("${send.topic}")
    private String sendTopic;
    @Value("${send.producer}")
    private String sendProducer;

    @Bean
    public Producer getProduct() {
        Properties producerProperties = new Properties();
        producerProperties.put(PropertyKeyConst.ProducerId, sendProducer);
        producerProperties.put(PropertyKeyConst.AccessKey, accessKeyID);
        producerProperties.put(PropertyKeyConst.SecretKey, accessKeySecret);
        producerProperties.put(PropertyKeyConst.ONSAddr, address);
        Producer producer = ONSFactory.createProducer(producerProperties);
        producer.start();
        System.out.println("producer启动");
        return producer;
    }

    public String getSendTopic() {
        return sendTopic;
    }
}
